/**
 * 
 */

/**
 * @author Bernhard Denner
 * @author Maximilian Csuk
 * @author Konrad Paumann
 */

public class CTree<Node, Edge> extends Tree<Node, Edge> {

	public CTree(Node nodeDesc) {
		super(nodeDesc);
	}
	
	private Tree<Node, Edge> find(Tree<Node, Edge> root, Node n) {
		TreeIteratorInterface<Tree<Node, Edge>, Node, Edge> nit = root.getNodeIterator();
		while(nit.hasNext()) {
			Tree<Node, Edge> node = nit.next();
			if (node.getNodeDesc() == n)
				return node;
			return find(node, n);
		}
		return null;
	}
	
	public boolean connected(Node a, Node b) {
		Tree<Node, Edge> na = find(this, a);
		if (na == null) // a not found
			return false;
		Tree<Node, Edge> nb = find(na, b);
		if (nb == null) // b not found under a
			return false;
		return true; // b found under a
	}

}
